<template>
  <li :class="{line:checked}">
    <label>
      <!--v-model脏数据-->
      <input type="checkbox" v-model="checked"  />
      <!--<span>{{item.text}}</span>-->
      <slot :text="item.text"></slot>
    </label>
    <button class="btn btn-danger" @click="delTask">删除</button>
  </li>
</template>

<script>
    export default {
        name: "todo-item",
        props:["item"],
        computed:{
          checked:{
            get(){return this.item.checked},
            set(val){
              //解决v-model的脏数据问题
              this.$bus.$emit("checked",this.item.id,val)
            }
          }
        },
        methods:{
          delTask(){
            //跟app进行通信 将需要删除的这条数据的id传递给app
            this.$bus.$emit("delTask",this.item.id)
          }
        }
    }
</script>

<style scoped>
  /*new*/
  li:hover{
    background: pink;
  }
  li:hover button{
    display: block;
  }
  .line{
    position: relative;
  }
  .line:after{
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    margin: auto;
    margin-left: 27px;
    display: block;
    content: "";
    width: 80%;
    height: 2px;
    background: red;
  }

  /*item*/
  li {
    list-style: none;
    height: 36px;
    line-height: 36px;
    padding: 0 5px;
    border-bottom: 1px solid #ddd;
  }

  li label {
    float: left;
    cursor: pointer;
  }

  li label li input {
    vertical-align: middle;
    margin-right: 6px;
    position: relative;
    top: -1px;
  }

  li button {
    float: right;
    margin-top: 3px;
    display: none;
  }

  li:before {
    content: initial;
  }

  li:last-child {
    border-bottom: none;
  }
</style>
